// LSL script generated: RLV-New.RLV_MENU.DV_RLV_ENVI.lslp Sun May  2 00:09:51 Westeuropäische Sommerzeit 2010
integer attachment = 1;
string cmdname;
key victim;
list gMenu = [];
list statesMenu = [1,0,0,0,0,0,0,0];
key ToucherID;
integer channel_dialog;
integer listen_id;
string msg = "Enviorment Settings";
list sideMenu = [" ","Back"," "];
integer changes;

llRlvSay(string command){
    if ((attachment == 1)) {
        llOwnerSay(("@" + command));
    }
    else  {
        llSay(-1812221819,(((((cmdname + ",") + ((string)victim)) + ",") + "@") + command));
    }
}

MakeRLVState(){
    if ((attachment == 1)) {
        if ((llList2Integer(statesMenu,0) == 1)) makeDefault();
        if ((llList2Integer(statesMenu,1) == 1)) makeBlack();
        if ((llList2Integer(statesMenu,2) == 1)) makeWhite();
        if ((llList2Integer(statesMenu,3) == 1)) makeStrange();
        if ((llList2Integer(statesMenu,4) == 1)) makeRandom();
        if ((llList2Integer(statesMenu,5) == 1)) llRlvSay("setenv=n");
    }
}
makeDefault(){
    (statesMenu = [1,0,0,0,0,changes,0,0]);
    llRlvSay("setenv_scenegamma:1.0=force");
    llRlvSay("setenv_ambientr:0.34=force");
    llRlvSay("setenv_ambientg:0.35=force");
    llRlvSay("setenv_ambientb:0.35=force");
    llRlvSay("setenv_ambienti:0.35=force");
}

makeBlack(){
    (statesMenu = [0,1,0,0,0,changes,0,0]);
    llRlvSay("setenv_scenegamma:0.0=force");
    llRlvSay("setenv_ambientr:0.0=force");
    llRlvSay("setenv_ambientg:0.0=force");
    llRlvSay("setenv_ambientb:0.0=force");
    llRlvSay("setenv_ambienti:0.0=force");
}

makeWhite(){
    (statesMenu = [0,0,1,0,0,changes,0,0]);
    llRlvSay("setenv_scenegamma:10.0=force");
    llRlvSay("setenv_ambientr:1.0=force");
    llRlvSay("setenv_ambientg:1.0=force");
    llRlvSay("setenv_ambientb:1.0=force");
    llRlvSay("setenv_ambienti:1.0=force");
}

makeStrange(){
    (statesMenu = [0,0,0,1,0,changes,0,0]);
    llRlvSay("setenv_scenegamma:1.0=force");
    llRlvSay("setenv_ambienti:0.99=force");
    llRlvSay("setenv_ambientr:0.99=force");
    llRlvSay("setenv_ambientg:0.0=force");
    llRlvSay("setenv_ambientb:0.99=force");
}
makeRandom(){
    (statesMenu = [0,0,0,0,1,changes,0,0]);
    integer _rand;
    (_rand = ((integer)llFrand(99)));
    llRlvSay((("setenv_scenegamma:0." + ((string)_rand)) + "=force"));
    (_rand = ((integer)llFrand(99)));
    llRlvSay((("setenv_ambienti:0." + ((string)_rand)) + "=force"));
    (_rand = ((integer)llFrand(99)));
    llRlvSay((("setenv_ambientr:0." + ((string)_rand)) + "=force"));
    (_rand = ((integer)llFrand(99)));
    llRlvSay((("setenv_ambientg:0." + ((string)_rand)) + "=force"));
    (_rand = ((integer)llFrand(99)));
    llRlvSay((("setenv_ambientb:0." + ((string)_rand)) + "=force"));
}
makeMenu(){
    (gMenu = []);
    (gMenu += sideMenu);
    if ((llList2Integer(statesMenu,0) == 1)) (gMenu += "[x]Default");
    else  (gMenu += "[ ]Default");
    if ((llList2Integer(statesMenu,1) == 1)) (gMenu += "[x]Black");
    else  (gMenu += "[ ]Black");
    if ((llList2Integer(statesMenu,2) == 1)) (gMenu += "[x]White");
    else  (gMenu += "[ ]White");
    if ((llList2Integer(statesMenu,3) == 1)) (gMenu += "[x]Strange");
    else  (gMenu += "[ ]Strange");
    if ((llList2Integer(statesMenu,4) == 1)) (gMenu += "[x]Random");
    else  (gMenu += "[ ]Random");
    if ((llList2Integer(statesMenu,5) == 1)) (gMenu += "[x]Change");
    else  (gMenu += "[ ]Change");
    (channel_dialog = (-1 * ((integer)("0x" + llGetSubString(((string)llGetKey()),-5,-1)))));
    (listen_id = llListen(channel_dialog,"",NULL_KEY,""));
    llDialog(ToucherID,msg,gMenu,channel_dialog);
    llSetTimerEvent(45.0);
}

llLRP(integer element_new,integer placeinlist){
    (statesMenu = llListReplaceList(statesMenu,[element_new],placeinlist,placeinlist));
}

default {

    state_entry() {
    }

    
    listen(integer channel,string name,key id,string message) {
        llListenRemove(listen_id);
        llSetTimerEvent(0.0);
        if ((message == "[ ]Default")) {
            llLRP(1,0);
            makeDefault();
            makeMenu();
        }
        if ((message == "[x]Default")) {
            llLRP(1,0);
            makeDefault();
            makeMenu();
        }
        if ((message == "[ ]Black")) {
            llLRP(1,1);
            makeBlack();
            makeMenu();
        }
        if ((message == "[x]Black")) {
            llLRP(1,1);
            makeBlack();
            makeMenu();
        }
        if ((message == "[ ]White")) {
            llLRP(1,2);
            makeWhite();
            makeMenu();
        }
        if ((message == "[x]White")) {
            llLRP(1,2);
            makeWhite();
            makeMenu();
        }
        if ((message == "[ ]Strange")) {
            llLRP(1,3);
            makeStrange();
            makeMenu();
        }
        if ((message == "[x]Strange")) {
            llLRP(1,3);
            makeStrange();
            makeMenu();
        }
        if ((message == "[ ]Random")) {
            llLRP(1,4);
            makeRandom();
            makeMenu();
        }
        if ((message == "[x]Random")) {
            llLRP(1,4);
            makeRandom();
            makeMenu();
        }
        if ((message == "[ ]Change")) {
            llLRP(1,5);
            llRlvSay("setenv=n");
            makeMenu();
            (changes = 1);
        }
        if ((message == "[x]Change")) {
            llLRP(0,5);
            llRlvSay("setenv=y");
            makeMenu();
            (changes = 0);
        }
        if ((message == "Back")) llMessageLinked(-4,1337,"DV_MAIN_RLV",ToucherID);
    }

    
    on_rez(integer on) {
    }

    
    link_message(integer sender,integer num,string str,key id) {
        if ((num == 1337)) {
            if ((str == llGetScriptName())) {
                llMessageLinked(-4,1338,llGetScriptName(),NULL_KEY);
                (ToucherID = id);
                makeMenu();
            }
        }
        if ((num == 1338)) {
            if ((str == "attachment")) (attachment = 1);
            else  if ((str == "device")) (attachment = 0);
            else  if ((str != llGetScriptName())) {
                llListenRemove(listen_id);
            }
        }
        if ((num == 1339)) {
            if ((str == "ON_REZ")) {
                MakeRLVState();
            }
            if ((str == "RESET")) {
                (statesMenu = [1,0,0,0,0,0,0,0]);
            }
        }
        if ((num == 1329)) {
            (victim = ((key)str));
            (cmdname = ((string)llGetKey()));
        }
    }

  	
  	timer() {
        llSetTimerEvent(0.0);
        llListenRemove(listen_id);
    }
}
